from rest_framework import serializers
from users.models import MyUser, Position


class UserSerializer(serializers.ModelSerializer):
    class Meta:
        model = MyUser
        exclude = ["password", "groups", "user_permissions", "is_active", "is_staff"]


class UserInfoStockSerializer(serializers.ModelSerializer):
    """
    用于在查询金额信息
    """

    class Meta:
        model = MyUser
        fields = ['id', 'cny_free', 'cny_freezed']


class PositionSerializer(serializers.ModelSerializer):
    user = UserInfoStockSerializer

    class Meta:
        model = Position
        fields = '__all__'
        read_only_fields = ('id', 'num_free', 'num_freezed', 'stock')
